#include "type.h"

struct type * type_create ( 
  int kind, 
  struct param_list * params, 
  struct type * rtype )
{
 struct type *a = malloc(sizeof(*a));

 a->kind = kind;
 a->params = params;
 a->rtype = rtype;

 return a;
}

void type_print(struct type * t)
{
  if (!t) return;

  switch (t->kind)
  {
    case TYPE_KIND_INTEGER:
      printf("int "); break;
    case TYPE_KIND_CHARACTER:
      printf("char "); break;
    case TYPE_KIND_STRING:
      printf("string "); break;
    case TYPE_KIND_BOOLEAN:
      printf("boolean "); break;
    case TYPE_KIND_VOID:
      printf("void "); break;
    case TYPE_KIND_FUNCTION:
       type_print(t->rtype); break;
  }
}


int type_compare(struct type * a, struct type * b)
{
  if (!a || !b) return 0;
  //if match, return 1, else 0
  //if func, compare return type
  int a_type = (a->kind == TYPE_KIND_FUNCTION) ? a->rtype->kind : a->kind ;
  int b_type = (b->kind == TYPE_KIND_FUNCTION) ? b->rtype->kind : b->kind ;
  return a_type == b_type;
}

